cmake_minimum_required(VERSION 3.21.1)
option(LINK_INSIGHT "Link Qt Insight Tracker library" ON)
option(BUILD_QDS_COMPONENTS "Build design studio components" ON)

set(CMAKE_PROJECT_NAME HUAPI_QtQuick)
project(${CMAKE_PROJECT_NAME} LANGUAGES CXX)

if(WIN32)
    set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/output/windows)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OUTPUT_DIR})

find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick Widgets)

if (Qt6_VERSION VERSION_GREATER_EQUAL 6.3)
    qt_standard_project_setup()
endif()




set(CMAKE_AUTOMOC ON)    # QT 中设置部分关键的编译选项
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)




message(">>> compile customized universal library ")  # 编译自定义的通用库
file(GLOB_RECURSE UNI_HEADER_FILES ${PROJECT_SOURCE_DIR}/include/*.h)
file(GLOB_RECURSE UNI_SRC_FILES ${PROJECT_SOURCE_DIR}/source/*.cpp)
set(LIBRARY_NAME ${CMAKE_PROJECT_NAME}_Lib)
add_subdirectory(source) # 编译自定义的通用库




# message(">>> add executable ${CMAKE_PROJECT_NAME} ")   # 项目的根目录程序
# set(CMAKE_TARGET_NAME ${CMAKE_PROJECT_NAME})
if(CMAKE_TARGET_NAME)
    if (WIN32)
        qt6_add_executable(${CMAKE_TARGET_NAME} WIN32 src/main.cpp)
    elseif(ANDROID)
        qt6_add_executable(${CMAKE_TARGET_NAME} src/main.cpp)
        qt_finalize_executable(${CMAKE_TARGET_NAME})
    endif()

    qt6_add_resources(${CMAKE_TARGET_NAME} "configuration"
        PREFIX "/"
        FILES
            qtquickcontrols2.conf
    )

    target_link_libraries(${CMAKE_TARGET_NAME} PRIVATE
        Qt6::Core
        Qt6::Gui
        Qt6::Qml
        Qt6::Quick
        Qt6::Widgets
    )
endif()

set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/qml)
set(QML_IMPORT_PATH ${QT_QML_OUTPUT_DIRECTORY}
    CACHE STRING "Import paths for Qt Creator's code model"
    FORCE
)




set(APP_NAME HUAPI_QtQuick_App)  # 添加项目主程序，名称为 HUAPI_QtQuick_App
message(">>> add executable ${APP_NAME} ")
if (APP_NAME)
    add_subdirectory(HUAPI_QtQuick)
endif()




# set(IMG_VIEWER_APP_NAME QImgViewer)  # 添加 ImageViewer 可执行程序
if(IMG_VIEWER_APP_NAME)
    add_subdirectory(QImgViewer)
endif()



message(">>> compile universal QML Modules components")    # 编译通用 QML 模块组件
if (BUILD_QDS_COMPONENTS)
    include(${CMAKE_CURRENT_SOURCE_DIR}/qmlcomponents)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/qmlmodules)

if (LINK_INSIGHT)
    include(${CMAKE_CURRENT_SOURCE_DIR}/insight)
endif ()

set(QML_IMPORT_PATH ${PROJECT_BINARY_DIR}/qml # make IDEs aware of the QML import path
    CACHE PATH "Path to the custom QML components defined by the project")
